<?php
/***
* @version $Id: usercp_sendusername.php 336 2007-01-23 08:12:56Z flexiondotorg $
* @copyright (c) 2006 - 2007 Flexion.Org
*            (c) 2004 - 2005 Project Minerva
*            (c) 2001 - 2006 phpBB Group
* @license   http://opensource.org/licenses/gpl-license.php GNU Public License
***/

if ( !defined('IN_R3BORN') )
{
	die('Hacking attempt');
}

if ( isset($_POST['submit']) )
{
   $email = ( !empty($_POST['email']) ) ? trim(strip_tags(htmlspecialchars($_POST['email']))) : '';

   $sql = "SELECT user_id, username, user_email, user_active, user_lang
      FROM " . USERS_TABLE . "
      WHERE user_email = '" . str_replace("\'", "''", $email) . "'";
   if ( $result = $db->sql_query($sql) )
   {
      if ( $row = $db->sql_fetchrow($result) )
      {
         if ( !$row['user_active'] )
         {
            message_die(GENERAL_MESSAGE, $lang['No_send_account_inactive']);
         }

         $username = $row['username'];
         $user_id = $row['user_id'];

         include($root_path . 'includes/class_emailer.'.$phpEx);
         $emailer = new emailer($config['smtp_delivery']);

         $emailer->from($config['board_email']);
         $emailer->replyto($config['board_email']);

         $emailer->use_template('user_username_reminder', $row['user_lang']);
         $emailer->email_address($row['user_email']);
         $emailer->set_subject($lang['Username_reminder']);

         $emailer->assign_vars(array(
            'SITENAME' => $config['sitename'],
            'USERNAME' => $username,
            'EMAIL_SIG' => (!empty($config['board_email_sig'])) ? str_replace('<br />', "\n", "-- \n" . $config['board_email_sig']) : '')
         );
         $emailer->send();
         $emailer->reset();

         $template->assign_vars(array(
            'META' => '<meta http-equiv="refresh" content="15;url=' . append_sid("index.$phpEx") . '">')
         );

         $message = $lang['User_reminder_sent'] . '<br /><br />' . sprintf($lang['Click_return_index'],  '<a href="' . append_sid("index.$phpEx") . '">', '</a>');

         message_die(GENERAL_MESSAGE, $message);
      }
      else
      {
         message_die(GENERAL_MESSAGE, $lang['No_email_match']);
      }
   }
   else
   {
      message_die(GENERAL_ERROR, 'Could not obtain user information for sendusername', '', __LINE__, __FILE__, $sql);
   }
}
else
{
   $email = '';
}

//
// Output basic page
//
page_header();

$template->set_filenames(array(
   'body' => 'profile_send_user.tpl')
);

$template->assign_vars(array(
   'EMAIL' => $email,

   'L_SEND_USERNAME' => $lang['Send_username'],
   'L_ITEMS_REQUIRED' => $lang['Items_required'],
   'L_EMAIL_ADDRESS' => $lang['Email_address'],
   'L_SUBMIT' => $lang['Submit'],
   'L_RESET' => $lang['Reset'],

   'S_HIDDEN_FIELDS' => '',
   'S_PROFILE_ACTION' => append_sid("register.$phpEx?mode=sendusername"))
);

$template->pparse('body');

page_footer();

?>